package com.lagou.homework.stage01.module04.copyFile;

import java.io.File;
import java.util.Scanner;
import java.util.concurrent.Executor;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class MainTest {
    private static String sPath;
    private static String dPath;
    private static ExecutorService executorService = Executors.newFixedThreadPool(10);

    private static void copyFile(String sp,String dp) {
        File file = new File(sp);

        String dp1 = dp + '\\' + file.getName();
        if (file.isFile()) {
            executorService.submit((new CopyFileThread(sp, dp1)));
        } else if (file.isDirectory()) {
            File[] filesArray = file.listFiles();
            for (File tf : filesArray) {
                String sp1 = sp + '\\' + tf.getName();
                copyFile(sp1, dp1);
            }
        } else {
            System.out.println("Illegal input !");
        }
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        System.out.println("Please input source file or directory :");
        sPath = sc.next();
        System.out.println("Please input destination path :");
        dPath = sc.next();

        copyFile(sPath,dPath);
        executorService.shutdown();
    }
}
